package com.example.learnspringboot.common;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 功能:拦截器规则
 * 说明:在这里进行拦截,在interceptor里进行
 * 作者:每天都要敲代码
 * 日期:2023/12/11 16:06
 */
//@Configuration表示这是一个配置类
@Configuration
public class InterceptorConfig extends WebMvcConfigurationSupport {
    @Override
    /*
   继承WebMvcConfigurationSupport,addInterceptors为其提供的方法
     */
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor()) //配置jwt拦截器的规则
                .addPathPatterns("/**") //拦截所有路径
                .excludePathPatterns("/login");
        super.addInterceptors(registry);
    }

//    以bean方法注入到spring容器当中去
    @Bean
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }
}
